package com.test.demo.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.example.common_library.view.image.ZoomImageView;
import com.test.demo.R;
import com.test.demo.main.bean.MediumBean;


public class RecyclerItemImageHolder extends RecyclerItemBaseHolder {

    public final static String TAG = "RecyclerItemImageHolder";

    protected Context context;
    ZoomImageView iv_zoom_image;

    public RecyclerItemImageHolder(Context context, View v) {
        super(v);
        this.context = context;
        iv_zoom_image = v.findViewById(R.id.iv_zoom_image);

    }

    public void onBind(final int position, MediumBean videoModel) {
        RequestOptions options = new RequestOptions().diskCacheStrategy(DiskCacheStrategy.RESOURCE);
        Glide.with(context)
                .asBitmap()
                .load(videoModel.getResId())
                .apply(options).into(new SimpleTarget<Bitmap>() {
            @Override
            public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                int width = resource.getWidth();
                int height = resource.getHeight();
                if (width >= height) {
                    iv_zoom_image.setScaleType(ImageView.ScaleType.FIT_CENTER);
                } else {
                    iv_zoom_image.setScaleType(ImageView.ScaleType.CENTER_CROP);
                }
                iv_zoom_image.setImageBitmap(resource);
            }
        });

    }


   OnItemLongListener onLongListener;

    public interface OnItemLongListener {
        void onLongClick();
    }


    public void setOnItemLongListener1(OnItemLongListener onLongListener) {
        this.onLongListener = onLongListener;
    }
}
